﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=tfXb2WnRlrF78kRQ2D9YgLsd"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<title>百度地图</title>
</head>
<body>
<div id="allmap"></div> 
</body>

</html>
<script type="text/javascript">


var map = new BMap.Map("allmap");            // 创建Map实例
var point = new BMap.Point(110.326, 25.2696);    // 创建点坐标
map.centerAndZoom(point,13);                     // 初始化地图,设置中心点坐标和地图级别。
map.enableScrollWheelZoom();                            //启用滚轮放大缩小
map.addControl(new BMap.ScaleControl());//比例尺
map.addControl(new BMap.OverviewMapControl({isOpen: true}));               //添加缩略地图控件

var polyline = new BMap.Polyline([], {strokeColor:"red", strokeWeight:6, strokeOpacity:0.5});
var LngLat = polyline.getPath();

map.addEventListener("click",function(e){
	point = e.point;
	
});

function showPolyline(){
	polyline.setPath(LngLat);
	//map.clearOverlays();
	map.addOverlay(polyline);
}

var nail = 0;
function showAddress(x,y,b) {
	var _point = new BMap.Point(y,x); 	

	BMap.Convertor.translate(_point,0,translateCallback); //真实经纬度转成百度坐标
	if(b != 0)
		nail = b;
}
translateCallback = function (point){
	map.clearOverlays();
	var marker = new BMap.Marker(point);
	if(nail != 0)
		map.centerAndZoom(point,map.getZoom());
	map.addOverlay(marker);
	var labelgps = new BMap.Label("I believe I can fly..",{offset:new BMap.Size(20,-10)});
	marker.setLabel(labelgps); //添加GPS标注
}		
		

function addAddress(x,y) {		
	var point_ = new BMap.Point(y,x); 	
	map.centerAndZoom(point_, map.getZoom());  
	
	//var marker = new BMap.Marker(point_);
	//map.addOverlay(marker);
	
	LngLat.push(point_);
	var html = LngLat.length;
	var label = new BMap.Label(html,{position : point_,offset: new BMap.Size(-5, -15)});  // 创建文本标注对象
	label.setStyle({color : "red",fontSize : "12px",height : "20px",lineHeight : "20px",fontFamily:"微软雅黑"});
	map.addOverlay(label);   
	
	showPolyline();
}

</script>





